package com.itheima.springboot02_01condition;

import com.itheima.springboot02_01condition.config.MyImportBeanDefinitionRegistrar;
import com.itheima.springboot02_01condition.config.MyImportSelectors;
import com.itheima.springboot02_01condition.config.UserConfig;
import com.itheima.springboot02_01condition.pojo.Apple;
import com.itheima.springboot02_01condition.pojo.User;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Import;

@SpringBootApplication
//@Import(User.class)
//@Import(UserConfig.class)
//@Import(MyImportSelectors.class)
@Import({MyImportBeanDefinitionRegistrar.class})
/**
 * /**
 * Import4中用法：
 *  1. 导入Bean
 *  2. 导入配置类
 *  3. 导入ImportSelector的实现类。
 *  4. 导入ImportBeanDefinitionRegistrar实现类
 */
public class SpringBoot0201conditionApplication {

    public static void main(String[] args) {

        //启动spring-boot项目 并返回一个IOC容器对象
        ConfigurableApplicationContext applicationContext = SpringApplication.run(SpringBoot0201conditionApplication.class, args);

        //从IOC容器中获取对象
        //如果没有UserConfig作为配置文件,就无法创建对象
        User user = applicationContext.getBean(User.class);
        System.out.println(user);

        //从IOC容器中获取对象
        Apple apple = applicationContext.getBean(Apple.class);
        System.out.println(apple);
    }

}
